﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Profile;
using PayRoller.Code;
using HySoft.Cash.Business;
using System.Data;
using HySoft.Cash.Structure;
using System.Web.UI.WebControls;
using System.Web.SessionState;

namespace PayRoller.Member
{
    public class ChangePwd : MemberParent, IRequiresSessionState
    {
        // Fields
        protected Button Button1;
        protected TextBox txtComfirmPwd;
        protected TextBox txtNewPwd;
        protected TextBox txtOldPwd;

        // Methods
        protected void Button1_Click(object sender, EventArgs e)
        {
            TorginfoBN obn = new TorginfoBN(this.Page);
            obn.QuerySid(Convert.ToInt32(base.OrgSid));
            DataTable list = obn.GetList();
            if (list.Rows.Count > 0)
            {
                if (list.Rows[0]["PassWord"].ToString().Trim().Equals(this.txtOldPwd.Text))
                {
                    TorginfoDT detail = obn.Get(Convert.ToInt32(base.OrgSid));
                    detail.Sid = Convert.ToInt32(base.OrgSid);
                    detail.PassWord = this.txtNewPwd.Text;
                    obn.Edit(detail);
                    obn.Dispose();
                    obn = null;
                    base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Error,fill it again!');</script>");
                }
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.CheckLogin();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Button1.Attributes.Add("onclick", "return Check1();");
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
